48 typedef unsigned int speed_t;
67 void append(
const unsigned char& byte);
68 void append(
const unsigned char *data,
const size_t& size);
71 void remove(
const size_t& i,
const size_t& len = 1);
73 const unsigned char *data()
const;
76 unsigned char byte(
const size_t& i);
81 std::vector<unsigned char> m_script;
101 namespace CreatePackets
174 namespace CreateSensors
180 class CliffFrontLeft;
181 class CliffFrontRight;
185 class CliffLeftSignal;
186 class CliffFrontLeftSignal;
187 class CliffFrontRightSignal;
188 class CliffRightSignal;
189 class CargoBayAnalogSignal;
190 class CargoBayDigitalInputs;
193 class BatteryTemperature;
195 class BatteryCapacity;
200 class WheelDropRight;
202 class WheelDropCaster;
251 bool isConnected()
const;
253 void setPassiveMode();
262 bool write(
const unsigned char& c);
263 bool write(
const unsigned char *data,
const size_t& len);
279 int read(
unsigned char *data,
const size_t& len);
288 bool blockingRead(
unsigned char *data,
const size_t& size,
unsigned timeout = 25);
294 return blockingRead(reinterpret_cast<unsigned char *>(&data),
sizeof(T),
295 timeout ? timeout :
sizeof(T) * 7);
298 void setLeds(
const bool& advance,
const bool& play,
const unsigned char& color,
const unsigned char& brightness);
300 void drive(
const short& velocity,
const short& radius);
301 void driveDirect(
const short& left,
const short& right);
302 inline void driveStraight(
const short& speed) { driveDirect(speed, speed); }
315 void turn(
const short& angle,
const unsigned short& speed);
323 void move(
const short& millimeters,
const unsigned short& speed);
329 void spin(
const short& speed);
336 short angularVelocity()
const;
341 bool setBaudRate(
const unsigned char& baudCode);
343 void setDistance(
const int distance);
344 void setAngle(
const int angle);
382 void setRefreshRate(
const unsigned short& refreshRate);
383 const unsigned short& refreshRate()
const;
390 static Create *instance();
402 pthread_mutex_lock(&m_mutex);
409 pthread_mutex_unlock(&m_mutex);
418 void setLocalBaudRate(
const speed_t& baudRate);
426 inline void lazyDelete(T *&ptr)
431 inline timeval timeOfDay()
const
435 GetSystemTimeAsFileTime(&ft);
436 unsigned long t = (ULONGLONG)ft.dwLowDateTime + ((ULONGLONG)(ft.dwHighDateTime) << 32);
439 tv.tv_usec = t % 1000L;
440 tv.tv_sec = (t - tv.tv_usec) / 1000L;
444 gettimeofday(&ret, NULL);
449 inline bool hasRequiredTimePassed(
const timeval& timestamp)
const
452 timeval current = timeOfDay();
454 timersub(¤t, ×tamp, &result);
455 const long msecs = result.tv_sec * 1000 + result.tv_usec / 1000;
456 return msecs > m_refreshRate;
458 #pragma message ("Create library not yet implemented for Windows")
463 inline double timevalToFloat(
const timeval& tv)
465 return ((
double)tv.tv_sec) + ((double)tv.tv_usec / 1000000.0);
468 inline float deg2rad(
const float& deg)
470 return deg / 180.0 *
PI;
475 void updateSensorPacket1();
476 void updateSensorPacket2(
bool forceUpdate =
false);
477 void updateSensorPacket3();
478 void updateSensorPacket4();
479 void updateSensorPacket5();
483 unsigned short m_refreshRate;
490 timeval timestamps[5];
497 mutable CreateSensors::PlayButton *m_playButton;
498 mutable CreateSensors::AdvanceButton *m_advanceButton;
500 mutable CreateSensors::Wall *m_wall;
501 mutable CreateSensors::CliffLeft *m_cliffLeft;
502 mutable CreateSensors::CliffFrontLeft *m_cliffFrontLeft;
503 mutable CreateSensors::CliffFrontRight *m_cliffFrontRight;
504 mutable CreateSensors::CliffRight *m_cliffRight;
505 mutable CreateSensors::VirtualWall *m_virtualWall;
507 mutable CreateSensors::WallSignal *m_wallSignal;
508 mutable CreateSensors::CliffLeftSignal *m_cliffLeftSignal;
509 mutable CreateSensors::CliffFrontLeftSignal *m_cliffFrontLeftSignal;
510 mutable CreateSensors::CliffFrontRightSignal *m_cliffFrontRightSignal;
511 mutable CreateSensors::CliffRightSignal *m_cliffRightSignal;
512 mutable CreateSensors::CargoBayAnalogSignal *m_cargoBayAnalogSignal;
513 mutable CreateSensors::CargoBayDigitalInputs *m_cargoBayDigitalInputs;
515 mutable CreateSensors::IR *m_ir;
517 mutable CreateSensors::ChargingState *m_chargingState;
518 mutable CreateSensors::BatteryTemperature *m_batteryTemperature;
519 mutable CreateSensors::BatteryCharge *m_batteryCharge;
520 mutable CreateSensors::BatteryCapacity *m_batteryCapacity;
522 mutable CreateSensors::Angle *m_angle;
523 mutable CreateSensors::Distance *m_distance;
525 mutable CreateSensors::BumpLeft *m_bumpLeft;
526 mutable CreateSensors::BumpRight *m_bumpRight;
528 mutable CreateSensors::WheelDropLeft *m_wheelDropLeft;
529 mutable CreateSensors::WheelDropRight *m_wheelDropRight;
530 mutable CreateSensors::WheelDropCaster *m_wheelDropCaster;
536 pthread_mutex_t m_mutex;